package cn.edu.zzu.demo01Thread;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 1.倒计时
 * 2.获取时间
 */
public class TestSleepThread04 implements Runnable {
    @Override
    public void run() {
        //倒计时
        int i = 10 ;
        while (i>=0){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+i);
            i--;
        }

        //时间
        Date date = new Date(System.currentTimeMillis());
        while (true){
            System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            date = new Date(System.currentTimeMillis());
        }
    }

    public static void main(String[] args) {
        new Thread(new TestSleepThread04(),"倒计时 ").start();
    }
}

